package com.hyh.fireworks.config;

import com.hyh.fireworks.common.constant.StringConstants;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author Summerday
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    FireworksProperties fireworksProperties;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String os = System.getProperty("os.name");
        String uploadDir = fireworksProperties.getUploadDir();
        if(os.toLowerCase().startsWith(StringConstants.OS_WINDOWS)){
            registry.addResourceHandler("/upload/**")
                    .addResourceLocations("file:///" +
                            uploadDir);
        }else{
            registry.addResourceHandler("/upload/**")
                    .addResourceLocations("file:"+ uploadDir);
        }

    }
}
